<template>
  <div class="header"></div>
  <div class="loginWraper">
    <div id="loginform" class="loginBox">
      <form class="form-horizontal" action="">
        <div class="account">
          <svg-icon
            name="account"
            width="26px"
            height="26px"
            class="svg-icon"
          ></svg-icon>
          <input
            id="text"
            name=""
            type="text"
            placeholder="账号"
            class="input size-L"
          />
        </div>
        <div class="password">
          <svg-icon
            name="password"
            class="svg-icon"
            width="26px"
            height="26px"
          ></svg-icon>
          <input
            id=""
            name=""
            type="password"
            placeholder="密码"
            class="input size-L"
          />
        </div>

        <div class="button-area">
          <div class="formControls col-xs-8 col-xs-offset-3">
            <input
              @click="login"
              name=""
              type="submit"
              class="btn btn-success radius size-btn"
              value="&nbsp;登&nbsp;&nbsp;&nbsp;&nbsp;录&nbsp;"
            />
            <input
              name=""
              type="reset"
              class="btn btn-default radius size-btn"
              value="&nbsp;取&nbsp;&nbsp;&nbsp;&nbsp;消&nbsp;"
            />
          </div>
        </div>
      </form>
    </div>
  </div>
  <div class="footer">Copyright 鱿鱼溪学院 by edu v1.1</div>
</template>

<script setup lang="ts">
import { reactive } from 'vue'
import { useRouter } from 'vue-router'
//引入用户相关的小仓库
import useUserStore from '@/store/modules/user1'
import { layer } from '@layui/layer-vue'
import getTime from '@/utils/time.ts'

let $router = useRouter()
let useStore1 = useUserStore()

//收集账号密码的数据
let loginForm = reactive({ username: 'admin', password: '111111' })

//登录按钮的回调
const login = () => {
  useStore1
    .userLogin(loginForm)
    .then((data: any) => {
      // console.log(data)
      layer.msg(`${data} ${getTime()}好`, { icon: 1, time: 2000 })
      // $router.push('/')
    })
    .catch((err) => {
      // ElNotification({
      //   type: 'error',
      //   message: err
      // })
      layer.msg(err, { icon: 5, time: 2000 })
    })
}
</script>

<style scoped lang="scss">
.header {
  top: 0;
  height: 60px;
  background: #426374 url(@/assets/images/logo.png) no-repeat 0 center;
}
.header,
.footer {
  position: absolute;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 99;
}
.loginWraper {
  position: absolute;
  width: 100%;
  left: 0;
  top: 0;
  bottom: 0;
  right: 0;
  z-index: 1;
  background: #3283ac url(@/assets/images/admin-login-bg.jpg) no-repeat center;
}
.loginBox {
  position: absolute;
  width: 617px;
  height: 330px;
  background: url(@/assets/images/admin-loginform-bg.png) no-repeat;
  left: 50%;
  top: 50%;
  margin-left: -309px;
  margin-top: -184px;
  padding-top: 38px;
}
.loginBox .input {
  width: 360px;
  border: 1px solid #ddd;
  display: inline-block;
  -webkit-transition: all 0.2s linear 0s;
  -moz-transition: all 0.2s linear 0s;
  -o-transition: all 0.2s linear 0s;
  transition: all 0.2s linear 0s;
}
input[type='text']:focus {
  outline: none;
}
input[type='password']:focus {
  outline: none;
}

.form-horizontal {
  margin-left: 140px;
  margin-top: 30px;
}
.form-horizontal .form-label {
  margin-top: 3px;
  text-align: right;
  margin-right: 5px;
}
.password {
  margin-top: 20px;
}
.button-area {
  margin-left: 20px;
}
.input.size-L {
  font-size: 16px;
  padding: 8px;
  height: 24px;
}
.size-btn {
  padding-left: 15px;
  margin-top: 40px;
  padding-right: 15px;
  padding-top: 8px;
  padding-bottom: 8px;
  margin-right: 10px;
}

.radius {
  border-radius: 4px;
}
//这里对图标组件进行了相对定位，进行了微调
.svg-icon {
  display: inline-block;
  margin-right: 5px;
  position: relative;
  top: 8px;
  right: 15px;
  cursor: pointer;
}
/* 按钮样式 */
.btn {
  display: inline-block;
  box-sizing: border-box;
  cursor: pointer;
  text-align: center;
  font-weight: 400;
  white-space: nowrap;
  vertical-align: middle;
  -moz-padding-start: npx;
  -moz-padding-end: npx;
  border: solid 1px #ddd;
  background-color: #fff;
  width: auto;
  *zoom: 1;
  *overflow: visible;
  -webkit-transition: background-color 0.1s linear;
  -moz-transition: background-color 0.1s linear;
  -o-transition: background-color 0.1s linear;
  transition: background-color 0.1s linear;
  font-size: 15px;
}

.btn-success {
  color: #fff;
  background-color: #5eb95e;
  border-color: #5eb95e;
}

.btn-default {
  background-color: #e6e6e6;
  border-color: #e6e6e6;
}

.footer {
  height: 46px;
  line-height: 46px;
  bottom: 0;
  text-align: center;
  color: #fff;
  font-size: 12px;
  background-color: #426374;
  font-style: italic;
}
</style>
